package com.glacier.cloud.order.service.impl;

import com.glacier.cloud.order.entity.dto.cmd.OrderCreatCmd;
import com.glacier.cloud.order.entity.dto.cmd.ProductStockLockCmd;
import com.glacier.cloud.order.remote.ProductClientService;
import com.glacier.cloud.order.service.ProductService;
import com.glacier.framework.component.dto.response.Response;
import com.glacier.framework.component.dto.response.StatusCode;
import com.glacier.framework.component.exception.BizException;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;

/**
 * date 2024-01-06 16:43
 *
 * @author glacier
 * @version 1.0
 */
@Service
public class ProductServiceImpl implements ProductService {
    @Resource
    private ProductClientService productClientService;
    @Override
    public void lockProductStock(OrderCreatCmd command, Long orderId) {
        Response<Integer> lockStock = productClientService.lockStock(
                new ProductStockLockCmd(orderId, command.getCustomerUserId(), command.getProducts()));
        if (!StatusCode.isSuccess(lockStock.getCode())) {
            throw new BizException("锁定库存失败");
        }
    }
}
